{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import collections\n",
    "import math\n",
    "import os\n",
    "import random\n",
    "from tempfile import gettempdir\n",
    "import zipfile\n",
    "\n",
    "import numpy as np\n",
    "from six.moves import urllib\n",
    "from six.moves import xrange  # pylint: disable=redefined-builtin\n",
    "import tensorflow as tf\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "filename=\"QuanSongCi.txt\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def read_data(filename):\n",
    "    with open(filename, encoding=\"utf-8\") as f:\n",
    "        data = f.read()\n",
    "    data = list(data)\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def build_dataset(words, n_words):\n",
    "  \"\"\"Process raw inputs into a dataset.\"\"\"\n",
    "  count = [['UNK', -1]]\n",
    "  count.extend(collections.Counter(words).most_common(n_words - 1))\n",
    "  dictionary = dict()\n",
    "  for word, _ in count:\n",
    "    dictionary[word] = len(dictionary)\n",
    "  data = list()\n",
    "  unk_count = 0\n",
    "  for word in words:\n",
    "    index = dictionary.get(word, 0)\n",
    "    if index == 0:  # dictionary['UNK']\n",
    "      unk_count += 1\n",
    "    data.append(index)\n",
    "  count[0][1] = unk_count\n",
    "  reversed_dictionary = dict(zip(dictionary.values(), dictionary.keys()))\n",
    "  return data, count, dictionary, reversed_dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data size 1903073\n"
     ]
    }
   ],
   "source": [
    "vocabulary = read_data(filename)\n",
    "print('Data size', len(vocabulary))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['潘', '阆', '\\n', '\\n', '酒', '泉', '子', '（', '十', '之', '一', '）', '\\n', '\\n', '长', '忆', '钱', '塘', '，', '不', '是', '人', '寰', '是', '天', '上', '。', '万', '家', '掩', '映', '翠', '微', '间', '。', '处', '处', '水', '潺', '潺']\n"
     ]
    }
   ],
   "source": [
    "print(vocabulary[0:40])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "vocabulary_size = 5000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data, count, dictionary, reverse_dictionary = build_dataset(vocabulary,vocabulary_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Most common words (+UNK) [['UNK', 1196], ('。', 149620), ('\\n', 117070), ('，', 108451), ('、', 19612)]\n",
      "Sample data [1503, 1828, 2, 2, 40, 613, 47, 9, 111, 117] ['潘', '阆', '\\n', '\\n', '酒', '泉', '子', '（', '十', '之']\n"
     ]
    }
   ],
   "source": [
    "print('Most common words (+UNK)', count[:5])\n",
    "print('Sample data', data[:10], [reverse_dictionary[i] for i in data[:10]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data_index = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Step 3: Function to generate a training batch for the skip-gram model.\n",
    "def generate_batch(batch_size, num_skips, skip_window):\n",
    "  global data_index\n",
    "  assert batch_size % num_skips == 0\n",
    "  assert num_skips <= 2 * skip_window\n",
    "  batch = np.ndarray(shape=(batch_size), dtype=np.int32)\n",
    "  labels = np.ndarray(shape=(batch_size, 1), dtype=np.int32)\n",
    "  span = 2 * skip_window + 1  # [ skip_window target skip_window ]\n",
    "  buffer = collections.deque(maxlen=span)\n",
    "  if data_index + span > len(data):\n",
    "    data_index = 0\n",
    "  buffer.extend(data[data_index:data_index + span])\n",
    "  data_index += span\n",
    "  for i in range(batch_size // num_skips):\n",
    "    context_words = [w for w in range(span) if w != skip_window]\n",
    "    words_to_use = random.sample(context_words, num_skips)\n",
    "    for j, context_word in enumerate(words_to_use):\n",
    "      batch[i * num_skips + j] = buffer[skip_window]\n",
    "      labels[i * num_skips + j, 0] = buffer[context_word]\n",
    "    if data_index == len(data):\n",
    "#       buffer[:] = data[:span]\n",
    "      for word in data[:span]:\n",
    "        buffer.append(word)\n",
    "      data_index = span\n",
    "    else:\n",
    "      buffer.append(data[data_index])\n",
    "      data_index += 1\n",
    "  # Backtrack a little bit to avoid skipping words in the end of a batch\n",
    "  data_index = (data_index + len(data) - span) % len(data)\n",
    "  return batch, labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "batch, labels = generate_batch(batch_size=8, num_skips=2, skip_window=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1828 阆 -> 2 \n",
      "\n",
      "1828 阆 -> 1503 潘\n",
      "2 \n",
      " -> 2 \n",
      "\n",
      "2 \n",
      " -> 1828 阆\n",
      "2 \n",
      " -> 2 \n",
      "\n",
      "2 \n",
      " -> 40 酒\n",
      "40 酒 -> 2 \n",
      "\n",
      "40 酒 -> 613 泉\n"
     ]
    }
   ],
   "source": [
    "for i in range(8):\n",
    "  print(batch[i], reverse_dictionary[batch[i]],'->', labels[i, 0], reverse_dictionary[labels[i, 0]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "batch_size = 128\n",
    "embedding_size = 128  # Dimension of the embedding vector.\n",
    "skip_window = 1       # How many words to consider left and right.\n",
    "num_skips = 2         # How many times to reuse an input to generate a label.\n",
    "num_sampled = 64\n",
    "\n",
    "valid_size = 16     # Random set of words to evaluate similarity on.\n",
    "valid_window = 100  # Only pick dev samples in the head of the distribution.\n",
    "valid_examples = np.random.choice(valid_window, valid_size, replace=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "graph = tf.Graph()\n",
    "\n",
    "with graph.as_default():\n",
    "\n",
    "  # Input data.\n",
    "  train_inputs = tf.placeholder(tf.int32, shape=[batch_size])\n",
    "  train_labels = tf.placeholder(tf.int32, shape=[batch_size, 1])\n",
    "  valid_dataset = tf.constant(valid_examples, dtype=tf.int32)\n",
    "\n",
    "  # Ops and variables pinned to the CPU because of missing GPU implementation\n",
    "  with tf.device('/cpu:0'):\n",
    "    # Look up embeddings for inputs.\n",
    "    embeddings = tf.Variable(\n",
    "        tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))\n",
    "    embed = tf.nn.embedding_lookup(embeddings, train_inputs)\n",
    "\n",
    "    # Construct the variables for the NCE loss\n",
    "    nce_weights = tf.Variable(\n",
    "        tf.truncated_normal([vocabulary_size, embedding_size],\n",
    "                            stddev=1.0 / math.sqrt(embedding_size)))\n",
    "    nce_biases = tf.Variable(tf.zeros([vocabulary_size]))\n",
    "\n",
    "  # Compute the average NCE loss for the batch.\n",
    "  # tf.nce_loss automatically draws a new sample of the negative labels each\n",
    "  # time we evaluate the loss.\n",
    "  # Explanation of the meaning of NCE loss:\n",
    "  #   http://mccormickml.com/2016/04/19/word2vec-tutorial-the-skip-gram-model/\n",
    "  loss = tf.reduce_mean(\n",
    "      tf.nn.nce_loss(weights=nce_weights,\n",
    "                     biases=nce_biases,\n",
    "                     labels=train_labels,\n",
    "                     inputs=embed,\n",
    "                     num_sampled=num_sampled,\n",
    "                     num_classes=vocabulary_size))\n",
    "\n",
    "  # Construct the SGD optimizer using a learning rate of 1.0.\n",
    "  optimizer = tf.train.GradientDescentOptimizer(1.0).minimize(loss)\n",
    "\n",
    "  # Compute the cosine similarity between minibatch examples and all embeddings.\n",
    "  norm = tf.sqrt(tf.reduce_sum(tf.square(embeddings), 1, keep_dims=True))\n",
    "  normalized_embeddings = embeddings / norm\n",
    "  valid_embeddings = tf.nn.embedding_lookup(\n",
    "      normalized_embeddings, valid_dataset)\n",
    "  similarity = tf.matmul(\n",
    "      valid_embeddings, normalized_embeddings, transpose_b=True)\n",
    "\n",
    "  # Add variable initializer.\n",
    "  init = tf.global_variables_initializer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "num_steps = 400001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Initialized\n",
      "Average loss at step  0 :  200.14163208\n",
      "Nearest to 香: 炷, 飖, 显, 陪, 浅, 右, 鬟, 斝,\n",
      "Nearest to 长: 鶒, 斛, 楠, 樱, 愚, 尽, 汹, 崩,\n",
      "Nearest to 东: 劫, 镂, 革, 箭, B, 5, 潆, 镊,\n",
      "Nearest to 谁: 荑, 希, 宕, 服, 诧, 緺, 艮, 诘,\n",
      "Nearest to 夜: 驺, ）, 磐, 训, 苎, 罪, 霅, 玳,\n",
      "Nearest to 自: 狂, 勿, 聂, 候, 姨, 局, 沔, 邸,\n",
      "Nearest to 云: 凹, 宦, 奂, 嘹, 澶, 袝, 郑, 谭,\n",
      "Nearest to 此: 琮, 嚎, 醑, 璿, 慎, 揖, 跛, 僚,\n",
      "Nearest to 柳: 宵, 涧, 孕, 金, 搏, 著, 逐, 谤,\n",
      "Nearest to 歌: 伏, 探, 彪, 漉, 咫, 棹, 手, 3,\n",
      "Nearest to 日: 增, 憨, 饧, 斗, 颐, 迎, 小, 狨,\n",
      "Nearest to 好: 宁, 篯, 茹, 扉, 定, 1, 逮, 你,\n",
      "Nearest to 雨: 躇, 举, 迩, 趺, 鸟, 吁, 驭, 熬,\n",
      "Nearest to 重: 缯, 寐, 莎, 裕, 等, 速, 鞋, 硬,\n",
      "Nearest to 心: 埒, 鳞, 果, 蔡, 舜, 察, 打, 惜,\n",
      "Nearest to 子: 瑾, 迭, 喜, 祠, 尫, 縻, 6, 史,\n",
      "Average loss at step  2000 :  21.4460533435\n",
      "Average loss at step  4000 :  5.25505921388\n",
      "Average loss at step  6000 :  4.89152049494\n",
      "Average loss at step  8000 :  4.6867944001\n",
      "Average loss at step  10000 :  4.60088950729\n",
      "Nearest to 香: 炷, 浅, 绪, 右, 鬟, 欣, 陪, 飞,\n",
      "Nearest to 长: 斛, 鶒, 尽, 逼, 樱, 汹, 内, 鉴,\n",
      "Nearest to 东: 劫, 镂, 聊, 箭, 春, 葛, 5, 革,\n",
      "Nearest to 谁: 君, 朵, 希, 嗟, 还, 岂, 犹, 荑,\n",
      "Nearest to 夜: 驺, 入,  , 商, ）, 罪, 玳, 菩,\n",
      "Nearest to 自: 候, 狂, 勿, 邸, 令, 研, 插, 局,\n",
      "Nearest to 云: 墩, 付, 志, 远, 澶, 涪, 宦, 锵,\n",
      "Nearest to 此: 慎, 个, 醑, 遇, 别, 揖, 仕, 拓,\n",
      "Nearest to 柳: 孕, 宵, 逐, 涧, 金, 著, 减, 皂,\n",
      "Nearest to 歌: 探, 伏, 咽, 俯, 晓, 棹, 手, 咫,\n",
      "Nearest to 日: 增, 迎, 闹, 削, 况, 颐, 撼, 霸,\n",
      "Nearest to 好: 宁, 定, 春, 扉, 你, 1, 以, 坠,\n",
      "Nearest to 雨: 躇, 迩, 举, 鸟, 岂, 死,  , 趺,\n",
      "Nearest to 重:  , 等, 莎, 寐, 速, 劲, 也, 缯,\n",
      "Nearest to 心: 愠, 胸, 鳞, 果, 蔡, 早, 藕, 蒹,\n",
      "Nearest to 子: 阕, 祠, 皓, 喜, 曰, 投, 溶, 晚,\n",
      "Average loss at step  12000 :  4.57173123252\n",
      "Average loss at step  14000 :  4.45273600554\n",
      "Average loss at step  16000 :  4.47051165771\n",
      "Average loss at step  18000 :  4.5042622807\n",
      "Average loss at step  20000 :  4.44232403982\n",
      "Nearest to 香: 炷, 鬟, 浅, 绪, 靖, 右, 欣, 冷,\n",
      "Nearest to 长: 斛, 逼, 鶒, 尽, 转, 梧, 呷, 樱,\n",
      "Nearest to 东: 西, 劫, 葛, 聊, 春, 镂, 箭, 泸,\n",
      "Nearest to 谁: 君, 还, 岂, 朵, 我, 希, 嗟, 莫,\n",
      "Nearest to 夜: 入, 驺, 玳, 擘, 磐, 苎,  , 震,\n",
      "Nearest to 自: 候, 狂, 勿, 姨, 令, 邸, 局, 蛇,\n",
      "Nearest to 云: 墩, 涪, 志, 淡, 锵, 篱, 远, 谭,\n",
      "Nearest to 此: 慎, 仕, 个, 蒹, 遇, 拓, 醑, 别,\n",
      "Nearest to 柳: 孕, 逐, 涧, 皂, 金, 宵, 减, 搏,\n",
      "Nearest to 歌: 探, 伏, 咽, 莓, 棹, 漉, 俯, 手,\n",
      "Nearest to 日: 闹, 削, 增, 迎, 饧, 撼, 、, 霸,\n",
      "Nearest to 好: 宁, 春, 定, 你, 呷, 似, 扉, 屈,\n",
      "Nearest to 雨: 躇, 迩, 鸟, 举, 驭, 岂,  , 拚,\n",
      "Nearest to 重:  , 劲, 也, 等, 莎, 寐, 裕, 速,\n",
      "Nearest to 心: 愠, 胸, 早, 藕, 舜, 果, 惜, 寻,\n",
      "Nearest to 子: 阕, 皓, 瑾, 祠, 批, 溶, 投, 洼,\n",
      "Average loss at step  22000 :  4.38515652668\n",
      "Average loss at step  24000 :  4.34872857153\n",
      "Average loss at step  26000 :  4.35815920603\n",
      "Average loss at step  28000 :  4.41014011645\n",
      "Average loss at step  30000 :  4.32056360102\n",
      "Nearest to 香: 炷, 鬟, 浅, 靖, 冷, 绪, 右, 斝,\n",
      "Nearest to 长: 斛, 应, 尽, 鶒, 逼, 呷, 囗, 转,\n",
      "Nearest to 东: 西, 葛, 劫, 聊, 泸, 春, 讹, 柘,\n",
      "Nearest to 谁: 君, 还, 我, 岂, 希, 莫, 嗟, 焉,\n",
      "Nearest to 夜: 擘, 驺, 入, 补, 玳, 苎, 磐, ◎,\n",
      "Nearest to 自: 令, 勿, 狂, 姨, 候, 局, 瞰, {,\n",
      "Nearest to 云: 墩, 涪, 志, 醵, 远, 篱, 士, 窈,\n",
      "Nearest to 此: 慎, 仕, 个, 别, 遇, 蒹, 拓, 赣,\n",
      "Nearest to 柳: 孕, 皂, 涧, 逐, 荚, 搏, 减, 金,\n",
      "Nearest to 歌: 咽, 伏, 莓, 探, 阇, 手, 漉, 棹,\n",
      "Nearest to 日: 闹, 削, 稚, 饧, 迎, 撼, 囗, 增,\n",
      "Nearest to 好: 宁, 春, 你, 定, 呷, 赣, 对, 屈,\n",
      "Nearest to 雨: 躇, 迩, 鸟, 吁, 熬, 驭, 趺, 岂,\n",
      "Nearest to 重:  , 也, 劲, 裕, 等, 寐, 剡, 速,\n",
      "Nearest to 心: 愠, 寻, 胸, 早, 果, 藕, 惜, 臧,\n",
      "Nearest to 子: 批, 洼, 阕, 瑾, 皓, 投, 溶, 祠,\n",
      "Average loss at step  32000 :  4.16666887403\n",
      "Average loss at step  34000 :  4.20403824246\n",
      "Average loss at step  36000 :  4.22922311187\n",
      "Average loss at step  38000 :  4.19087642395\n",
      "Average loss at step  40000 :  4.18348505807\n",
      "Nearest to 香: 冷, 炷, 浅, 靖, 斝, 剖, 泞, 右,\n",
      "Nearest to 长: 斛, 鶒, 应, 逼, 转, 懋, 呷, 樱,\n",
      "Nearest to 东: 西, 泸, 聊, 劫, 葛, 柘, 翩, 讹,\n",
      "Nearest to 谁: 君, 我, 还, 岂, 莫, 焉, 践, 嗟,\n",
      "Nearest to 夜: 擘, 宵, 补, 驺, 对, 入, 苎, 玳,\n",
      "Nearest to 自: 勿, 令, 狂, {, 毒, 便, 姨, 局,\n",
      "Nearest to 云: 墩, 志, 窈, 坑, 欤, 涪, 枣, 澶,\n",
      "Nearest to 此: 慎, 仕, 个, 遇, 蒹, 拓, 别, 澈,\n",
      "Nearest to 柳: 孕, 涧, 皂, 逐, 减, 槐, 荚, 啜,\n",
      "Nearest to 歌: 咽, 阇, 伏, 莓, 探, 手, 播, 仁,\n",
      "Nearest to 日: 闹, 削, 囗, 况, 月, 撼, 稚, 咎,\n",
      "Nearest to 好: 春, 宁, 定, 你, 呷, 复, 总, 扉,\n",
      "Nearest to 雨: 躇, 迩, 鸟, 吁, 縠, 趺, 逊, 熬,\n",
      "Nearest to 重: 劲, 也,  , 等, 剡, 裕, 絇, 寐,\n",
      "Nearest to 心: 愠, 胸, 寻, 果, 惜, 早, 臧, 勺,\n",
      "Nearest to 子: 阕, 投, 曰, 祠, 批, 皓, 洼, 峥,\n",
      "Average loss at step  42000 :  4.21115063357\n",
      "Average loss at step  44000 :  4.19942818391\n",
      "Average loss at step  46000 :  4.24268494141\n",
      "Average loss at step  48000 :  4.28182505369\n",
      "Average loss at step  50000 :  4.2561221863\n",
      "Nearest to 香: 炷, 靖, 冷, 剖, 鬟, 斝, 泞, 哄,\n",
      "Nearest to 长: 斛, 应, 懋, 转, 逼, 嘱, 鶒, 娶,\n",
      "Nearest to 东: 西, 讹, 泸, 葛, 聊, 柘, 泽, 南,\n",
      "Nearest to 谁: 君, 还, 我, 岂, 焉, 莫, 践, 希,\n",
      "Nearest to 夜: 擘, 对, 入, 补, 驺, 宵, 玳, ◎,\n",
      "Nearest to 自: 令, 勿, 我, 狂, 姨, {, 便, 共,\n",
      "Nearest to 云: 墩, 窈, 坑, 枣, 霭, 志, 涪, 锵,\n",
      "Nearest to 此: 慎, 仕, 遇, 蒹, 赣, 拓, 前, 襜,\n",
      "Nearest to 柳: 孕, 涧, 皂, 槐, 减, 犊, 荚, 逐,\n",
      "Nearest to 歌: 咽, 阇, 莓, 播, 伏, 享, 笏, 手,\n",
      "Nearest to 日: 月, 闹, 魔, 囗, 削, 稚, 撼, 代,\n",
      "Nearest to 好: 春, 宁, 你, 定, 呷, 赣, 垠, 总,\n",
      "Nearest to 雨: 躇, 迩, 縠, 鸟, 熬, 驭, 逊, 墀,\n",
      "Nearest to 重: 劲, 再, 剡, 也, 裕, 絇,  , 桃,\n",
      "Nearest to 心: 愠, 胸, 勺, 早, 臧, 藕, 寻, 缣,\n",
      "Nearest to 子: 投, 批, 洼, 阕, 曙, 瑾, 囗, 皓,\n",
      "Average loss at step  52000 :  4.241991889\n",
      "Average loss at step  54000 :  4.19645114136\n",
      "Average loss at step  56000 :  4.23284709942\n",
      "Average loss at step  58000 :  4.25177131391\n",
      "Average loss at step  60000 :  4.17549593914\n",
      "Nearest to 香: 炷, 冷, 靖, 剖, 泞, 鬟, 斝, 瀹,\n",
      "Nearest to 长: 应, 斛, 懋, 转, 鶒, 嘱, 铸, 劳,\n",
      "Nearest to 东: 西, 讹, 南, 葛, 泸, 聊, 泽, 柘,\n",
      "Nearest to 谁: 还, 我, 君, 岂, 焉, 践, 莫, 琛,\n",
      "Nearest to 夜: 宵, 擘, 补, 对, a, ◎, 玳, 入,\n",
      "Nearest to 自: 令, 我, 共, 勿, 俱, 便, 驶, 毒,\n",
      "Nearest to 云: 墩, 窈, 霭, 坑, 枣, 士, 远, 峒,\n",
      "Nearest to 此: 慎, 仕, 遇, 今, 赣, 蒹, 践, 前,\n",
      "Nearest to 柳: 孕, 涧, 皂, 花, 杨, 槐, 犊, 荚,\n",
      "Nearest to 歌: 咽, 阇, 莓, 播, 笏, 伏, 莼, 犯,\n",
      "Nearest to 日: 月, 魔, 闹, 削, 疾, 稚, 囗, 年,\n",
      "Nearest to 好: 你, 宁, 春, 定, 赣, 呷, 总, 垠,\n",
      "Nearest to 雨: 躇, 迩, 縠, 熬, 逊, 吁, 墀, 鸟,\n",
      "Nearest to 重: 剡, 再, 劲, 絇, 裕, 朱, 也, 植,\n",
      "Nearest to 心: 愠, 勺, 胸, 寻, 早, 瞋, 缣, 渗,\n",
      "Nearest to 子: 批, 洼, 阕, 曙, 投, 曰, 峥, 瑾,\n",
      "Average loss at step  62000 :  4.09575289452\n",
      "Average loss at step  64000 :  4.10932233608\n",
      "Average loss at step  66000 :  4.1286824317\n",
      "Average loss at step  68000 :  4.1056220243\n",
      "Average loss at step  70000 :  4.10700163895\n",
      "Nearest to 香: 炷, 泞, 冷, 剖, 斝, 靖, 花, 困,\n",
      "Nearest to 长: 应, 斛, 懋, 鶒, 转, 樱, 宜, 逼,\n",
      "Nearest to 东: 西, 讹, 南, 泽, 斜, 聊, 泸, 柘,\n",
      "Nearest to 谁: 还, 岂, 我, 君, 焉, 践, 赊, 莫,\n",
      "Nearest to 夜: 宵, 擘, 对, a, 补, 僻, ◎, 驺,\n",
      "Nearest to 自: 我, 俱, 共, 令, 勿, 便, 驶, 毒,\n",
      "Nearest to 云: 墩, 窈, 坑, 霭, 枣, 欤, 撤, 雪,\n",
      "Nearest to 此: 慎, 仕, 遇, 今, 蒹, 赣, 澈, 践,\n",
      "Nearest to 柳: 孕, 涧, 杨, 皂, 槐, 减, 竹, 犊,\n",
      "Nearest to 歌: 咽, 阇, 播, 笏, 莼, 商, 莓, 伏,\n",
      "Nearest to 日: 月, 闹, 魔, 咎, 代, 削, 鄙, 囗,\n",
      "Nearest to 好: 春, 你, 宁, 定, 呷, 韶, 赣, 总,\n",
      "Nearest to 雨: 躇, 縠, 迩, 墀, 吁, 趺, 鸟, 露,\n",
      "Nearest to 重: 再, 劲, 絇, 剡, 巫, 九, 同, 叠,\n",
      "Nearest to 心: 勺, 愠, 胸, 果, 缣, 牒, 瞋, 渗,\n",
      "Nearest to 子: 投, 阕, 批, 曰, 曙, 洼, 祠, 峥,\n",
      "Average loss at step  72000 :  4.12792931187\n",
      "Average loss at step  74000 :  4.12749653244\n",
      "Average loss at step  76000 :  4.19424253035\n",
      "Average loss at step  78000 :  4.19764854658\n",
      "Average loss at step  80000 :  4.19037218118\n",
      "Nearest to 香: 炷, 靖, 泞, 瀹, 态, 哄, 剖, 花,\n",
      "Nearest to 长: 应, 懋, 斛, 嘱, 转, 当, 逼, 宜,\n",
      "Nearest to 东: 西, 讹, 南, 斜, 泽, 聊, 柘, 葛,\n",
      "Nearest to 谁: 还, 岂, 我, 君, 焉, 赊, 践, 琛,\n",
      "Nearest to 夜: 宵, 擘, 处, 对, a, ◎, 补, 袋,\n",
      "Nearest to 自: 我, 令, 俱, 共, 勿, 窝, 驶, 懒,\n",
      "Nearest to 云: 墩, 窈, 霭, 坑, 枣, 撤, 欤, 霆,\n",
      "Nearest to 此: 慎, 仕, 遇, 今, 赣, 蒹, 者, 践,\n",
      "Nearest to 柳: 杨, 皂, 涧, 孕, 竹, 槐, 垂, 花,\n",
      "Nearest to 歌: 咽, 阇, 笏, 播, 莓, 莼, 箫, 商,\n",
      "Nearest to 日: 月, 代, 魔, 年, 夕, 闹, 囗, 疾,\n",
      "Nearest to 好: 你, 春, 宁, 赣, 呷, 篯, 垠, 韶,\n",
      "Nearest to 雨: 縠, 躇, 迩, 驭, 墀, 熬, 露, 听,\n",
      "Nearest to 重: 再, 絇, 劲, 剡, 巫, 叠, 春, 裕,\n",
      "Nearest to 心: 勺, 愠, 胸, 缣, 已, 早, 瞋, 囷,\n",
      "Nearest to 子: 批, 曙, 投, 洼, 阕, 囗, 峥, 祠,\n",
      "Average loss at step  82000 :  4.17017575157\n",
      "Average loss at step  84000 :  4.13821794617\n",
      "Average loss at step  86000 :  4.18510776663\n",
      "Average loss at step  88000 :  4.17701851225\n",
      "Average loss at step  90000 :  4.09601376545\n",
      "Nearest to 香: 炷, 泞, 剖, 冷, 帐, 瀹, 靖, 斝,\n",
      "Nearest to 长: 应, 懋, 当, 斛, 嘱, 铸, 转, 劳,\n",
      "Nearest to 东: 西, 南, 斜, 讹, 泽, 柘, 聊, 葛,\n",
      "Nearest to 谁: 还, 岂, 我, 君, 焉, 莫, 赊, 琛,\n",
      "Nearest to 夜: 宵, 擘, a, 补, 僻, 对, ◎, 处,\n",
      "Nearest to 自: 我, 共, 俱, 令, 驶, 为, 便, 绸,\n",
      "Nearest to 云: 墩, 窈, 霭, 枣, 坑, 撤, 峒, 雪,\n",
      "Nearest to 此: 慎, 仕, 今, 遇, 之, 赣, 前, 纂,\n",
      "Nearest to 柳: 杨, 花, 涧, 皂, 孕, 槐, 竹, 釭,\n",
      "Nearest to 歌: 咽, 阇, 笏, 播, 欢, 箫, 莼, 躅,\n",
      "Nearest to 日: 月, 魔, 疾, 年, 夕, 代, 闹, 咎,\n",
      "Nearest to 好: 你, 春, 宁, 赣, 呷, 垠, 韶, 总,\n",
      "Nearest to 雨: 縠, 躇, 迩, 墀, 露, 熬, 淝, 螟,\n",
      "Nearest to 重: 再, 絇, 剡, 劲, 朱, 叠, 同, 巫,\n",
      "Nearest to 心: 勺, 缣, 愠, 胸, 瞋, 哉, 已, 果,\n",
      "Nearest to 子: 曙, 批, 洼, 阕, 峥, 投, 曰, 孙,\n",
      "Average loss at step  92000 :  4.04771314502\n",
      "Average loss at step  94000 :  4.08714230597\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  96000 :  4.05005251873\n",
      "Average loss at step  98000 :  4.07522579432\n",
      "Average loss at step  100000 :  4.05685265189\n",
      "Nearest to 香: 炷, 泞, 熏, 斝, 帐, 困, 剖, 态,\n",
      "Nearest to 长: 应, 懋, 宜, 樱, 当, 斛, 鶒, 转,\n",
      "Nearest to 东: 西, 南, 斜, 讹, 擒, 泽, 聊, 柘,\n",
      "Nearest to 谁: 还, 岂, 我, 君, 焉, 赊, 践, 暂,\n",
      "Nearest to 夜: 宵, 擘, a, 更, 对, ◎, 僻, 睛,\n",
      "Nearest to 自: 我, 俱, 共, 驶, 便, 勿, 懒, 为,\n",
      "Nearest to 云: 墩, 窈, 霭, 坑, 枣, 撤, 烟, 欤,\n",
      "Nearest to 此: 慎, 仕, 遇, 今, 之, 鞮, 割, 且,\n",
      "Nearest to 柳: 杨, 竹, 涧, 孕, 槐, 皂, 垂, 釭,\n",
      "Nearest to 歌: 咽, 阇, 播, 笏, 箫, 欢, 莼, 躅,\n",
      "Nearest to 日: 月, 代, 魔, 年, 夕, 咎, 鄙, 疾,\n",
      "Nearest to 好: 春, 你, 韶, 宁, 赣, 篯, 值, 垠,\n",
      "Nearest to 雨: 縠, 躇, 迩, 墀, 露, 雪, 螟, 淝,\n",
      "Nearest to 重: 再, 叠, 同, 絇, 劲, 巫, 九, 剡,\n",
      "Nearest to 心: 勺, 胸, 缣, 愠, 瞋, 果, 哉, 已,\n",
      "Nearest to 子: 曙, 阕, 祠, 批, 孙, 曰, 峥, 投,\n",
      "Average loss at step  102000 :  4.07948157907\n",
      "Average loss at step  104000 :  4.09228050399\n",
      "Average loss at step  106000 :  4.14393093264\n",
      "Average loss at step  108000 :  4.14714856672\n",
      "Average loss at step  110000 :  4.16486887348\n",
      "Nearest to 香: 炷, 泞, 熏, 态, 瀹, 哄, 靖, 帐,\n",
      "Nearest to 长: 应, 懋, 当, 嘱, 宜, 樱, 汹, 转,\n",
      "Nearest to 东: 西, 讹, 南, 斜, 泽, 柘, 聊, 俭,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 君, 争, 赊, 暂,\n",
      "Nearest to 夜: 宵, 擘, a, 处, ◎, 对, 袋, 坐,\n",
      "Nearest to 自: 俱, 我, 共, 驶, 令, 窝, 为, 勿,\n",
      "Nearest to 云: 墩, 窈, 霭, 坑, 枣, 撤, 矮, 烟,\n",
      "Nearest to 此: 慎, 仕, 今, 遇, 之, 者, 鞮, 割,\n",
      "Nearest to 柳: 杨, 皂, 垂, 竹, 涧, 槐, 孕, 釭,\n",
      "Nearest to 歌: 阇, 笏, 咽, 播, 箫, 欢, 莼, 莓,\n",
      "Nearest to 日: 月, 代, 夕, 年, 魔, 朝, 疾, 咎,\n",
      "Nearest to 好: 你, 春, 宁, 篯, 赣, 韶, 值, 芟,\n",
      "Nearest to 雨: 縠, 迩, 躇, 露, 墀, 听, 螟, 驭,\n",
      "Nearest to 重: 再, 絇, 叠, 巫, 同, 沚, 劲, 剡,\n",
      "Nearest to 心: 勺, 缣, 胸, 已, 愠, 术, 瞋, 墀,\n",
      "Nearest to 子: 曙, 批, 洼, 阕, 孙, 投, 囗, 峥,\n",
      "Average loss at step  112000 :  4.11361647522\n",
      "Average loss at step  114000 :  4.10589639008\n",
      "Average loss at step  116000 :  4.14602886784\n",
      "Average loss at step  118000 :  4.13804629254\n",
      "Average loss at step  120000 :  4.03176764619\n",
      "Nearest to 香: 炷, 熏, 泞, 帐, 剖, 瀹, 芳, 揉,\n",
      "Nearest to 长: 应, 懋, 当, 宜, 嘱, 申, 樱, 劳,\n",
      "Nearest to 东: 西, 南, 斜, 讹, 柘, 泽, 聊, 俭,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 君, 赊, 争, 暂,\n",
      "Nearest to 夜: 宵, a, 擘, 更, 鉴, 栩, 坐, 僻,\n",
      "Nearest to 自: 我, 共, 俱, 驶, 为, 人, 私, 绸,\n",
      "Nearest to 云: 墩, 窈, 霭, 坑, 枣, 撤, 烟, 远,\n",
      "Nearest to 此: 慎, 仕, 今, 遇, 之, 旧, 鞮, 赣,\n",
      "Nearest to 柳: 杨, 花, 皂, 竹, 槐, 垂, 涧, 孕,\n",
      "Nearest to 歌: 咽, 笏, 阇, 欢, 播, 箫, 话, 莼,\n",
      "Nearest to 日: 月, 夕, 疾, 魔, 代, 年, 篱, 咎,\n",
      "Nearest to 好: 你, 春, 宁, 韶, 赣, 众, 芟, 卑,\n",
      "Nearest to 雨: 縠, 迩, 躇, 露, 淝, 墀, 螟, 雪,\n",
      "Nearest to 重: 再, 叠, 絇, 同, 巫, 沚, 朱, 剡,\n",
      "Nearest to 心: 勺, 缣, 胸, 情, 已, 瞋, 墀, 哉,\n",
      "Nearest to 子: 曙, 孙, 批, 洼, 祠, 阕, 峥, 曰,\n",
      "Average loss at step  122000 :  4.03442310715\n",
      "Average loss at step  124000 :  4.05904787147\n",
      "Average loss at step  126000 :  4.00608016217\n",
      "Average loss at step  128000 :  4.03951625741\n",
      "Average loss at step  130000 :  4.04324365652\n",
      "Nearest to 香: 炷, 熏, 泞, 帐, 渐, 芳, 瀹, 斝,\n",
      "Nearest to 长: 应, 懋, 宜, 当, 樱, 申, 鶒, 铸,\n",
      "Nearest to 东: 西, 南, 斜, 讹, 泽, 擒, 聊, 柘,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 君, 暂, 赊, 争,\n",
      "Nearest to 夜: 宵, a, 擘, 更, ◎, 对, 僻, 栩,\n",
      "Nearest to 自: 俱, 我, 共, 驶, 便, 私, 为, 零,\n",
      "Nearest to 云: 墩, 窈, 霭, 坑, 撤, 枣, 烟, 翠,\n",
      "Nearest to 此: 慎, 仕, 今, 遇, 之, 割, 鞮, 张,\n",
      "Nearest to 柳: 杨, 竹, 槐, 垂, 杏, 皂, 釭, 涧,\n",
      "Nearest to 歌: 阇, 咽, 笏, 欢, 箫, 播, 话, 躅,\n",
      "Nearest to 日: 月, 代, 夕, 魔, 年, 篱, 咎, 鄙,\n",
      "Nearest to 好: 春, 你, 韶, 真, 摊, 值, 佳, □,\n",
      "Nearest to 雨: 縠, 躇, 迩, 雪, 墀, 露, 淝, 螟,\n",
      "Nearest to 重: 再, 叠, 同, 劲, 巫, 絇, 沚, 九,\n",
      "Nearest to 心: 勺, 缣, 胸, 哉, 瞋, 愠, 已, 意,\n",
      "Nearest to 子: 曙, 孙, 批, 祠, 曰, 阕, 峥, 洼,\n",
      "Average loss at step  132000 :  4.03613694155\n",
      "Average loss at step  134000 :  4.06369088089\n",
      "Average loss at step  136000 :  4.11830531836\n",
      "Average loss at step  138000 :  4.11116606891\n",
      "Average loss at step  140000 :  4.13481672466\n",
      "Nearest to 香: 炷, 熏, 帐, 态, 泞, 渐, 芳, 瀹,\n",
      "Nearest to 长: 应, 当, 懋, 宜, 申, 嘱, 樱, 汹,\n",
      "Nearest to 东: 西, 斜, 南, 讹, 柘, 薰, 俭, 泽,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 争, 赊, 君, 暂,\n",
      "Nearest to 夜: 宵, a, 处, 擘, 栩, 琴, ◎, 坐,\n",
      "Nearest to 自: 俱, 共, 我, 驶, 为, 窝, 令, 零,\n",
      "Nearest to 云: 窈, 墩, 霭, 枣, 坑, 撤, 烟, 扰,\n",
      "Nearest to 此: 慎, 仕, 今, 之, 遇, 者, 割, 鞮,\n",
      "Nearest to 柳: 杨, 竹, 垂, 皂, 梅, 槐, 杏, 釭,\n",
      "Nearest to 歌: 阇, 笏, 咽, 欢, 播, 箫, 话, 帚,\n",
      "Nearest to 日: 月, 夕, 代, 魔, 年, 朝, 篱, 疾,\n",
      "Nearest to 好: 你, 春, 篯, 佳, 值, 哥, 韶, 赣,\n",
      "Nearest to 雨: 縠, 迩, 躇, 听, 露, 番, 墀, 淝,\n",
      "Nearest to 重: 再, 叠, 沚, 巫, 同, 絇, 九, 壬,\n",
      "Nearest to 心: 勺, 缣, 术, 胸, 已, 墀, 哉, 愠,\n",
      "Nearest to 子: 曙, 批, 洼, 阕, 孙, 祠, 史, 峥,\n",
      "Average loss at step  142000 :  4.09528104949\n",
      "Average loss at step  144000 :  4.07267690325\n",
      "Average loss at step  146000 :  4.12367108297\n",
      "Average loss at step  148000 :  4.10260035443\n",
      "Average loss at step  150000 :  3.98820297599\n",
      "Nearest to 香: 熏, 炷, 芳, 帐, 花, 揉, 泞, 惋,\n",
      "Nearest to 长: 应, 当, 懋, 申, 宜, 樱, 际, 睿,\n",
      "Nearest to 东: 西, 南, 斜, 讹, 北, 柘, 嫦, 俭,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 君, 赊, 争, 暂,\n",
      "Nearest to 夜: 宵, 栩, a, 更, 晓, 擘, 梦, 鉴,\n",
      "Nearest to 自: 俱, 共, 我, 人, 为, 驶, 私, 应,\n",
      "Nearest to 云: 窈, 墩, 霭, 枣, 撤, 坑, 烟, 远,\n",
      "Nearest to 此: 慎, 仕, 今, 之, 遇, 旧, 割, 鞮,\n",
      "Nearest to 柳: 杨, 花, 垂, 竹, 梅, 槐, 釭, 皂,\n",
      "Nearest to 歌: 欢, 咽, 阇, 笏, 箫, 话, 播, 帚,\n",
      "Nearest to 日: 月, 夕, 疾, 篱, 昼, 魔, 代, 朝,\n",
      "Nearest to 好: 你, 春, 佳, 韶, 哥, 值, 众, 缺,\n",
      "Nearest to 雨: 縠, 迩, 躇, 露, 淝, 雪, 夏, 听,\n",
      "Nearest to 重: 再, 叠, 同, 沚, 端, 巫, 絇, 朱,\n",
      "Nearest to 心: 勺, 缣, 胸, 情, 墀, 哉, 已, 意,\n",
      "Nearest to 子: 曙, 孙, 批, 洼, 祠, 阕, 峥, 史,\n",
      "Average loss at step  152000 :  4.01123053312\n",
      "Average loss at step  154000 :  4.03911545157\n",
      "Average loss at step  156000 :  3.98202639508\n",
      "Average loss at step  158000 :  4.0210890919\n",
      "Average loss at step  160000 :  4.02526570272\n",
      "Nearest to 香: 熏, 炷, 帐, 泞, 斝, 渐, 困, 芳,\n",
      "Nearest to 长: 应, 当, 宜, 懋, 樱, 申, 鲐, 永,\n",
      "Nearest to 东: 西, 南, 斜, 北, 讹, 柘, 饪, 俭,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 争, 赊, 君, 暂,\n",
      "Nearest to 夜: 宵, 更, a, 对, 栩, 晓, 擘, 僻,\n",
      "Nearest to 自: 俱, 我, 便, 零, 私, 驶, 人, 共,\n",
      "Nearest to 云: 窈, 墩, 霭, 坑, 撤, 枣, 烟, 曙,\n",
      "Nearest to 此: 慎, 仕, 之, 今, 遇, 割, 旧, 且,\n",
      "Nearest to 柳: 杨, 竹, 杏, 槐, 垂, 釭, 梅, 袅,\n",
      "Nearest to 歌: 阇, 咽, 欢, 笏, 播, 话, 箫, 帚,\n",
      "Nearest to 日: 月, 代, 夕, 魔, 年, 篱, 况, 疾,\n",
      "Nearest to 好: 春, 你, 韶, 佳, 值, 哥, 缺, 篯,\n",
      "Nearest to 雨: 縠, 躇, 雪, 迩, 淝, 露, 墀, 番,\n",
      "Nearest to 重: 再, 叠, 同, 沚, 巫, 九, 劲, 絇,\n",
      "Nearest to 心: 勺, 缣, 哉, 术, 墀, 意, 胸, 瞋,\n",
      "Nearest to 子: 曙, 孙, 批, 祠, 洼, 史, 曰, 阕,\n",
      "Average loss at step  162000 :  4.01040790868\n",
      "Average loss at step  164000 :  4.05408534801\n",
      "Average loss at step  166000 :  4.07963464272\n",
      "Average loss at step  168000 :  4.08433572352\n",
      "Average loss at step  170000 :  4.10160008836\n",
      "Nearest to 香: 熏, 炷, 帐, 芳, 渐, 斝, 泞, 腻,\n",
      "Nearest to 长: 应, 当, 懋, 宜, 申, 永, 汹, 嘱,\n",
      "Nearest to 东: 西, 南, 斜, 讹, 薰, 北, 柘, 俭,\n",
      "Nearest to 谁: 还, 岂, 争, 焉, 我, 赊, 暂, 君,\n",
      "Nearest to 夜: 宵, a, 处, 栩, 坐, 对, 擘, 琴,\n",
      "Nearest to 自: 俱, 我, 共, 驶, 为, 零, 穆, 应,\n",
      "Nearest to 云: 窈, 霭, 墩, 枣, 撤, 坑, 烟, 仍,\n",
      "Nearest to 此: 慎, 仕, 之, 遇, 今, 割, 者, 旧,\n",
      "Nearest to 柳: 杨, 垂, 竹, 杏, 槐, 梅, 釭, 皂,\n",
      "Nearest to 歌: 阇, 笏, 欢, 咽, 箫, 播, 话, 帚,\n",
      "Nearest to 日: 月, 夕, 代, 魔, 朝, 年, 况, 疾,\n",
      "Nearest to 好: 你, 春, 哥, 佳, 值, 缺, 篯, 韶,\n",
      "Nearest to 雨: 縠, 躇, 迩, 听, 淝, 番, 露, 夏,\n",
      "Nearest to 重: 再, 叠, 同, 沚, 巫, 端, 絇, 九,\n",
      "Nearest to 心: 勺, 缣, 术, 已, 胸, 墀, 哉, ,\n",
      "Nearest to 子: 曙, 孙, 批, 阕, 洼, 史, 〓, 点,\n",
      "Average loss at step  172000 :  4.08592007351\n",
      "Average loss at step  174000 :  4.05193666446\n",
      "Average loss at step  176000 :  4.10660868812\n",
      "Average loss at step  178000 :  4.08004141796\n",
      "Average loss at step  180000 :  3.9501770736\n",
      "Nearest to 香: 熏, 炷, 芳, 花, 揉, 帐, 泞, 惋,\n",
      "Nearest to 长: 应, 当, 懋, 宜, 申, 睿, 跎, 永,\n",
      "Nearest to 东: 西, 南, 北, 斜, 讹, 柘, 阆, 嫦,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 争, 暂, 君, 难,\n",
      "Nearest to 夜: 宵, 更, 栩, a, 晓, 梦, 对, 僻,\n",
      "Nearest to 自: 俱, 人, 我, 私, 为, 记, 共, 应,\n",
      "Nearest to 云: 窈, 霭, 撤, 墩, 枣, 坑, 烟, 仍,\n",
      "Nearest to 此: 慎, 之, 仕, 今, 遇, 割, 旧, 也,\n",
      "Nearest to 柳: 杨, 花, 梅, 垂, 槐, 杏, 竹, 釭,\n",
      "Nearest to 歌: 欢, 阇, 咽, 话, 笏, 箫, 播, 帚,\n",
      "Nearest to 日: 月, 夕, 朝, 疾, 魔, 篱, 代, 昼,\n",
      "Nearest to 好: 你, 佳, 哥, 值, 缺, 春, 众, 卑,\n",
      "Nearest to 雨: 縠, 迩, 雪, 淝, 躇, 露, 夏, 番,\n",
      "Nearest to 重: 再, 叠, 同, 端, 沚, 絇, 巫, 慵,\n",
      "Nearest to 心: 勺, 缣, 情, 哉, 意, 胸, 嗟, 术,\n",
      "Nearest to 子: 曙, 孙, 批, 洼, 祠, 点, 阕, 史,\n",
      "Average loss at step  182000 :  4.00239810348\n",
      "Average loss at step  184000 :  4.0235127275\n",
      "Average loss at step  186000 :  3.96015756834\n",
      "Average loss at step  188000 :  4.00097042441\n",
      "Average loss at step  190000 :  4.01412210596\n",
      "Nearest to 香: 熏, 炷, 帐, 泞, 芳, 渐, 斝, 困,\n",
      "Nearest to 长: 应, 当, 宜, 懋, 常, 申, 樱, 永,\n",
      "Nearest to 东: 西, 南, 北, 斜, 讹, 阆, 刚, 柘,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 争, 暂, 君, 赊,\n",
      "Nearest to 夜: 宵, a, 栩, 靸, 对, 更, 至, 晓,\n",
      "Nearest to 自: 俱, 零, 便, 我, 私, 应, 疑, 脯,\n",
      "Nearest to 云: 霭, 墩, 窈, 坑, 撤, 枣, 曙, 烟,\n",
      "Nearest to 此: 慎, 仕, 之, 割, 今, 遇, 其, 也,\n",
      "Nearest to 柳: 杨, 槐, 杏, 垂, 竹, 釭, 梅, 袅,\n",
      "Nearest to 歌: 欢, 阇, 话, 咽, 播, 箫, 帚, 笏,\n",
      "Nearest to 日: 月, 代, 夕, 魔, 年, 篱, 况, 朝,\n",
      "Nearest to 好: 你, 春, 佳, 哥, 值, 缺, 韶, 谏,\n",
      "Nearest to 雨: 縠, 躇, 雪, 迩, 淝, 夏, 露, 番,\n",
      "Nearest to 重: 再, 叠, 同, 沚, 九, 巫, 魔, 絇,\n",
      "Nearest to 心: 勺, 缣, 术, 意, 哉, 胸, 墀, 已,\n",
      "Nearest to 子: 孙, 曙, 批, 点, 史, 阕, 祠, 洼,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  192000 :  3.99877443278\n",
      "Average loss at step  194000 :  4.02519116545\n",
      "Average loss at step  196000 :  4.07443074775\n",
      "Average loss at step  198000 :  4.06825880098\n",
      "Average loss at step  200000 :  4.08581805253\n",
      "Nearest to 香: 炷, 熏, 帐, 芳, 泞, 花, 渐, 瀹,\n",
      "Nearest to 长: 应, 当, 宜, 永, 懋, 申, 常, 际,\n",
      "Nearest to 东: 西, 斜, 南, 北, 阆, 讹, 薰, 柘,\n",
      "Nearest to 谁: 还, 岂, 焉, 争, 我, 赊, 否, 暂,\n",
      "Nearest to 夜: 宵, a, 处, 栩, 对, 晓, 坐, 鉴,\n",
      "Nearest to 自: 俱, 记, 我, 零, 应, 共, 为, 穆,\n",
      "Nearest to 云: 霭, 窈, 枣, 墩, 撤, 坑, 烟, 仍,\n",
      "Nearest to 此: 慎, 之, 仕, 割, 今, 遇, 也, 旧,\n",
      "Nearest to 柳: 杨, 垂, 杏, 竹, 槐, 梅, 釭, 草,\n",
      "Nearest to 歌: 欢, 阇, 笏, 话, 播, 箫, 咽, 帚,\n",
      "Nearest to 日: 月, 夕, 朝, 魔, 代, 年, 于, 况,\n",
      "Nearest to 好: 你, 佳, 春, 哥, 值, 缺, 众, 要,\n",
      "Nearest to 雨: 縠, 躇, 迩, 淝, 番, 夏, 雪, 秤,\n",
      "Nearest to 重: 再, 叠, 同, 巫, 端, 沚, 九, 絇,\n",
      "Nearest to 心: 勺, 缣, 术, 已, 意, 劈, 哉, 墀,\n",
      "Nearest to 子: 曙, 批, 孙, 阕, 点, 洼, 史, 峥,\n",
      "Average loss at step  202000 :  4.062046386\n",
      "Average loss at step  204000 :  4.03475398862\n",
      "Average loss at step  206000 :  4.08978990614\n",
      "Average loss at step  208000 :  4.05502456892\n",
      "Average loss at step  210000 :  3.9292972734\n",
      "Nearest to 香: 熏, 炷, 芳, 揉, 泞, 花, 麝, 帐,\n",
      "Nearest to 长: 应, 申, 永, 当, 懋, 际, 常, 跎,\n",
      "Nearest to 东: 西, 南, 北, 阆, 斜, 刚, 柘, 讹,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 争, 君, 暂, 难,\n",
      "Nearest to 夜: 宵, 栩, 更, a, 晓, 梦, 至, 坐,\n",
      "Nearest to 自: 俱, 记, 我, 私, 应, 人, 零, 为,\n",
      "Nearest to 云: 霭, 窈, 撤, 枣, 墩, 曙, 雾, 仍,\n",
      "Nearest to 此: 慎, 之, 仕, 今, 割, 旧, 也, 遇,\n",
      "Nearest to 柳: 杨, 垂, 杏, 槐, 花, 梅, 釭, 竹,\n",
      "Nearest to 歌: 欢, 话, 箫, 阇, 咽, 笏, 播, 帚,\n",
      "Nearest to 日: 月, 夕, 朝, 魔, 昼, 疾, 代, 篱,\n",
      "Nearest to 好: 佳, 你, 哥, 缺, 值, 众, 春, 卑,\n",
      "Nearest to 雨: 縠, 雪, 淝, 躇, 迩, 露, 秤, 番,\n",
      "Nearest to 重: 再, 叠, 端, 同, 沚, 九, 巫, 絇,\n",
      "Nearest to 心: 勺, 缣, 嗟, 哉, 意, 术, 已, 墀,\n",
      "Nearest to 子: 曙, 批, 孙, 点, 阕, 洼, 史, 祠,\n",
      "Average loss at step  212000 :  3.98456085014\n",
      "Average loss at step  214000 :  4.00158796501\n",
      "Average loss at step  216000 :  3.95608431423\n",
      "Average loss at step  218000 :  3.97001666278\n",
      "Average loss at step  220000 :  4.0080352124\n",
      "Nearest to 香: 熏, 炷, 芳, 泞, 麝, 帐, 斝, 兽,\n",
      "Nearest to 长: 应, 当, 懋, 常, 申, 宜, 永, 际,\n",
      "Nearest to 东: 西, 南, 北, 斜, 阆, 刚, 讹, 嫦,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 争, 君, 暂, 赊,\n",
      "Nearest to 夜: 宵, 更, 栩, a, 靸, 晓, 对, 至,\n",
      "Nearest to 自: 俱, 零, 便, 记, 应, 我, 脯, 私,\n",
      "Nearest to 云: 霭, 墩, 窈, 撤, 坑, 曙, 烟, 枣,\n",
      "Nearest to 此: 慎, 之, 割, 仕, 也, 今, 且, 偏,\n",
      "Nearest to 柳: 杨, 杏, 槐, 垂, 竹, 釭, 梅, 袅,\n",
      "Nearest to 歌: 欢, 话, 阇, 箫, 帚, 笏, 咽, 播,\n",
      "Nearest to 日: 月, 夕, 代, 魔, 朝, 况, 年, 篱,\n",
      "Nearest to 好: 佳, 春, 你, 哥, 值, 缺, 恍, 谏,\n",
      "Nearest to 雨: 縠, 雪, 躇, 淝, 迩, 霭, 番, 秤,\n",
      "Nearest to 重: 再, 叠, 同, 九, 沚, 巫, 预, 絇,\n",
      "Nearest to 心: 勺, 缣, 术, 意, 哉, 劈, 墀, 嗟,\n",
      "Nearest to 子: 孙, 批, 曙, 史, 点, 阕, 韩, 洼,\n",
      "Average loss at step  222000 :  3.98919298041\n",
      "Average loss at step  224000 :  4.00753331923\n",
      "Average loss at step  226000 :  4.07852384794\n",
      "Average loss at step  228000 :  4.05070724297\n",
      "Average loss at step  230000 :  4.06480919957\n",
      "Nearest to 香: 炷, 熏, 帐, 芳, 泞, 斝, 花, 腻,\n",
      "Nearest to 长: 当, 应, 永, 常, 懋, 申, 际, 澹,\n",
      "Nearest to 东: 西, 南, 阆, 斜, 北, 讹, 柘, 薰,\n",
      "Nearest to 谁: 还, 岂, 争, 焉, 我, 否, 君, 赊,\n",
      "Nearest to 夜: 宵, 栩, a, 处, 靸, 坐, 夕, 对,\n",
      "Nearest to 自: 记, 俱, 应, 便, 为, 脯, 穆, 疑,\n",
      "Nearest to 云: 霭, 墩, 窈, 枣, 撤, 坑, 烟, 扰,\n",
      "Nearest to 此: 慎, 之, 割, 仕, 今, 也, 遇, 偏,\n",
      "Nearest to 柳: 杨, 杏, 垂, 槐, 竹, 梅, 釭, 草,\n",
      "Nearest to 歌: 欢, 阇, 话, 箫, 播, 笏, 帚, 唱,\n",
      "Nearest to 日: 夕, 月, 朝, 年, 魔, 代, 况, 午,\n",
      "Nearest to 好: 佳, 你, 春, 哥, 值, 缺, 恍, 要,\n",
      "Nearest to 雨: 縠, 躇, 迩, 雪, 淝, 夏, 番, 秤,\n",
      "Nearest to 重: 再, 叠, 端, 同, 巫, 沚, 絇, 襄,\n",
      "Nearest to 心: 勺, 缣, 术, 劈, 哉, 已, 嗟, 胸,\n",
      "Nearest to 子: 孙, 曙, 批, 阕, 史, 点, 洼, 韩,\n",
      "Average loss at step  232000 :  4.03714651549\n",
      "Average loss at step  234000 :  4.01716401672\n",
      "Average loss at step  236000 :  4.06781526947\n",
      "Average loss at step  238000 :  4.03776678157\n",
      "Average loss at step  240000 :  3.92192861998\n",
      "Nearest to 香: 熏, 炷, 芳, 花, 泞, 麝, 腻, 帐,\n",
      "Nearest to 长: 应, 常, 永, 当, 际, 跎, 懋, 鲐,\n",
      "Nearest to 东: 西, 南, 北, 阆, 刚, 嫦, 柘, 讹,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 争, 君, 暂, 难,\n",
      "Nearest to 夜: 宵, 栩, 夕, 更, 晓, 至, a, 坐,\n",
      "Nearest to 自: 记, 俱, 私, 天, 人, 应, 零, 为,\n",
      "Nearest to 云: 霭, 窈, 撤, 墩, 曙, 烟, 雾, 仍,\n",
      "Nearest to 此: 慎, 之, 割, 今, 仕, 也, 偏, 旧,\n",
      "Nearest to 柳: 杨, 杏, 垂, 花, 槐, 釭, 梅, 竹,\n",
      "Nearest to 歌: 欢, 话, 箫, 帚, 阇, 咽, 播, 笏,\n",
      "Nearest to 日: 夕, 月, 昼, 魔, 朝, 年, 午, 疾,\n",
      "Nearest to 好: 佳, 春, 哥, 你, 缺, 值, 恍, 众,\n",
      "Nearest to 雨: 縠, 淝, 雪, 躇, 露, 迩, 秤, 霭,\n",
      "Nearest to 重: 再, 叠, 端, 同, 沚, 巫, 九, 絇,\n",
      "Nearest to 心: 勺, 缣, 嗟, 术, 意, 哉, 已, 情,\n",
      "Nearest to 子: 曙, 批, 洼, 点, 孙, 韩, 姜, 阕,\n",
      "Average loss at step  242000 :  3.96666492426\n",
      "Average loss at step  244000 :  3.98922545063\n",
      "Average loss at step  246000 :  3.94823119843\n",
      "Average loss at step  248000 :  3.95598254114\n",
      "Average loss at step  250000 :  3.97978758562\n",
      "Nearest to 香: 熏, 炷, 麝, 芳, 泞, 犀, 帐, 斝,\n",
      "Nearest to 长: 当, 常, 永, 应, 懋, 申, 宜, 际,\n",
      "Nearest to 东: 西, 南, 北, 阆, 刚, 嫦, 斜, 讹,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 君, 暂, 争, □,\n",
      "Nearest to 夜: 宵, 栩, a, 靸, 晓, 至, 夕, 更,\n",
      "Nearest to 自: 便, 俱, 零, 记, 应, 脯, 疑, 私,\n",
      "Nearest to 云: 霭, 墩, 窈, 撤, 曙, 烟, 坑, 雾,\n",
      "Nearest to 此: 慎, 之, 割, 仕, 今, 偏, 协, 挫,\n",
      "Nearest to 柳: 杨, 杏, 槐, 竹, 垂, 梅, 釭, 草,\n",
      "Nearest to 歌: 欢, 话, 箫, 阇, 帚, 播, 咽, 唱,\n",
      "Nearest to 日: 月, 夕, 代, 魔, 话, 疾, 篱, 朝,\n",
      "Nearest to 好: 佳, 你, 哥, 缺, 值, □, 恍, 春,\n",
      "Nearest to 雨: 縠, 雪, 躇, 淝, 霭, 迩, 秤, 夏,\n",
      "Nearest to 重: 再, 叠, □, 沚, 同, 巫, 魔, 九,\n",
      "Nearest to 心: 勺, 缣, 术, 意, 哉, 嗟, 劈, 墀,\n",
      "Nearest to 子: 孙, 点, 阕, 批, 曙, 史, 韩, 洼,\n",
      "Average loss at step  252000 :  3.98520274878\n",
      "Average loss at step  254000 :  4.01994080341\n",
      "Average loss at step  256000 :  4.04955866063\n",
      "Average loss at step  258000 :  4.0355671711\n",
      "Average loss at step  260000 :  4.04637835312\n",
      "Nearest to 香: 熏, 炷, 帐, 芳, 花, 泞, 斝, 麝,\n",
      "Nearest to 长: 当, 应, 永, 常, 际, 申, 宜, 懋,\n",
      "Nearest to 东: 西, 南, 阆, 北, 斜, 薰, 刚, 讹,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 争, 那, 赊, 否,\n",
      "Nearest to 夜: 宵, 栩, a, 晓, 靸, 坐, 夕, 处,\n",
      "Nearest to 自: 记, 应, 俱, 便, 疑, 穆, 脯, 又,\n",
      "Nearest to 云: 霭, 窈, 墩, 撤, 枣, 坑, 扰, 曙,\n",
      "Nearest to 此: 之, 慎, 割, 也, 今, 偏, 挫, 仕,\n",
      "Nearest to 柳: 杨, 杏, 槐, 竹, 垂, 梅, 草, 花,\n",
      "Nearest to 歌: 阇, 欢, 话, 唱, 箫, 播, 帚, 笏,\n",
      "Nearest to 日: 夕, 月, 朝, 魔, 年, 午, 话, 况,\n",
      "Nearest to 好: 佳, 哥, 你, 春, 缺, 值, 恍, 荀,\n",
      "Nearest to 雨: 縠, 躇, 迩, 淝, 秤, 雪, 柳, 番,\n",
      "Nearest to 重: 再, 叠, 同, 端, 沚, 还, 襄, 絇,\n",
      "Nearest to 心: 勺, 缣, 术, 嗟, 哉, 已, 檥, 意,\n",
      "Nearest to 子: 曙, 孙, 阕, 史, 批, 韩, 瑾, 洼,\n",
      "Average loss at step  262000 :  4.01460759151\n",
      "Average loss at step  264000 :  4.01445400798\n",
      "Average loss at step  266000 :  4.04730699337\n",
      "Average loss at step  268000 :  3.99856736529\n",
      "Average loss at step  270000 :  3.93594748259\n",
      "Nearest to 香: 熏, 炷, 麝, 芳, 泞, 腻, 花, 帐,\n",
      "Nearest to 长: 常, 应, 永, 当, 际, 跎, 鲐, 申,\n",
      "Nearest to 东: 西, 南, 北, 阆, 刚, 嫦, 柘, 讹,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 争, 暂, 君, 罕,\n",
      "Nearest to 夜: 宵, 栩, 晓, 夕, 更, 至, 梦, 对,\n",
      "Nearest to 自: 记, 私, 人, 应, 俱, 便, 疑, 吊,\n",
      "Nearest to 云: 霭, 窈, 撤, 墩, 曙, 雾, 欤, 烟,\n",
      "Nearest to 此: 之, 慎, 割, 今, 挫, 偏, 旧, 每,\n",
      "Nearest to 柳: 杨, 杏, 槐, 垂, 花, 竹, 草, 釭,\n",
      "Nearest to 歌: 欢, 话, 唱, 播, 箫, 阇, 帚, 舞,\n",
      "Nearest to 日: 夕, 月, 午, 魔, 昼, 年, 夜, 况,\n",
      "Nearest to 好: 佳, 缺, 哥, 你, 春, 恍, 值, 喜,\n",
      "Nearest to 雨: 縠, 淝, 躇, 雪, 露, 秤, 霭, 夏,\n",
      "Nearest to 重: 再, 叠, 同, 端, 沚, 九, 慵, 絇,\n",
      "Nearest to 心: 勺, 嗟, 缣, 术, 哉, 已, 意, 氤,\n",
      "Nearest to 子: 曙, 韩, 批, 洼, 点, 孙, 峥, 史,\n",
      "Average loss at step  272000 :  3.95415892816\n",
      "Average loss at step  274000 :  3.97889891458\n",
      "Average loss at step  276000 :  3.934035501\n",
      "Average loss at step  278000 :  3.94516944522\n",
      "Average loss at step  280000 :  3.95802237916\n",
      "Nearest to 香: 熏, 炷, 麝, 芳, 泞, 渐, 斝, 困,\n",
      "Nearest to 长: 常, 当, 永, 应, 申, 际, 懋, 宜,\n",
      "Nearest to 东: 西, 南, 北, 阆, 刚, 嫦, 斜, 讹,\n",
      "Nearest to 谁: 还, 岂, 我, 焉, 君, 那, 争, 否,\n",
      "Nearest to 夜: 宵, 至, 栩, 夕, 晓, 靸, 对, 近,\n",
      "Nearest to 自: 便, 记, 俱, 零, 脯, 疑, 应, 我,\n",
      "Nearest to 云: 霭, 墩, 曙, 烟, 窈, 撤, 雾, 坑,\n",
      "Nearest to 此: 之, 慎, 割, 偏, 今, 其, 每, 协,\n",
      "Nearest to 柳: 杨, 杏, 槐, 竹, 垂, 梅, 釭, 堤,\n",
      "Nearest to 歌: 欢, 话, 阇, 箫, 帚, 播, 唱, 咽,\n",
      "Nearest to 日: 月, 夕, 代, 况, 午, 魔, 朝, 话,\n",
      "Nearest to 好: 佳, 哥, 你, 缺, 值, 恍, 春, 喜,\n",
      "Nearest to 雨: 縠, 雪, 躇, 淝, 迩, 粤, 霭, 夏,\n",
      "Nearest to 重: 再, 叠, 沚, 端, 同, 呢, 珈, 襄,\n",
      "Nearest to 心: 勺, 缣, 术, 哉, 意, 嗟, 神, 劈,\n",
      "Nearest to 子: 点, 孙, 批, 阕, 曙, 韩, 洼, 姜,\n",
      "Average loss at step  282000 :  3.98071118188\n",
      "Average loss at step  284000 :  4.02480602634\n",
      "Average loss at step  286000 :  4.03614345789\n",
      "Average loss at step  288000 :  4.03126846409\n",
      "Average loss at step  290000 :  4.03610932148\n",
      "Nearest to 香: 炷, 熏, 芳, 花, 麝, 帐, 泞, 斝,\n",
      "Nearest to 长: 永, 当, 常, 应, 际, 平, 申, 鲐,\n",
      "Nearest to 东: 西, 阆, 南, 北, 斜, 刚, 薰, 讹,\n",
      "Nearest to 谁: 还, 岂, 焉, 难, 争, 我, 那, 否,\n",
      "Nearest to 夜: 宵, 栩, a, 晓, 近, 坐, 夕, 靸,\n",
      "Nearest to 自: 记, 应, 脯, 疑, 便, 共, 穆, 最,\n",
      "Nearest to 云: 霭, 窈, 墩, 撤, 枣, 雾, 烟, 扰,\n",
      "Nearest to 此: 慎, 之, 割, 今, 也, 偏, 挫, 仕,\n",
      "Nearest to 柳: 杨, 杏, 槐, 垂, 竹, 草, 花, 梅,\n",
      "Nearest to 歌: 阇, 欢, 唱, 箫, 播, 话, 笏, 帚,\n",
      "Nearest to 日: 夕, 月, 朝, 午, 魔, 时, 况, 代,\n",
      "Nearest to 好: 佳, 哥, 你, 缺, 值, 春, 恍, 喜,\n",
      "Nearest to 雨: 縠, 躇, 迩, 秤, 淝, 番, 雪, 芭,\n",
      "Nearest to 重: 再, 叠, 端, 襄, 同, 还, 慵, 沚,\n",
      "Nearest to 心: 勺, 术, 缣, 嗟, 檥, 哉, 神, 意,\n",
      "Nearest to 子: 史, 孙, 韩, 曙, 瑾, 阕, 洼, 批,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  292000 :  3.99458099389\n",
      "Average loss at step  294000 :  4.02084999728\n",
      "Average loss at step  296000 :  4.02599770665\n",
      "Average loss at step  298000 :  3.97839866054\n",
      "Average loss at step  300000 :  3.92573881316\n",
      "Nearest to 香: 熏, 麝, 炷, 芳, 花, 泞, 揉, 斝,\n",
      "Nearest to 长: 常, 永, 际, 应, 当, 跎, 鲐, 正,\n",
      "Nearest to 东: 西, 南, 北, 阆, 刚, 柘, 嫦, 斜,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 争, 仍, 那, 罕,\n",
      "Nearest to 夜: 宵, 晓, 栩, 夕, 更, 梦, 对, 至,\n",
      "Nearest to 自: 记, 应, 人, 私, 便, 疑, 俱, 我,\n",
      "Nearest to 云: 霭, 撤, 窈, 墩, 曙, 雾, 烟, 鸾,\n",
      "Nearest to 此: 之, 慎, 割, 今, 也, 偏, 挫, 旧,\n",
      "Nearest to 柳: 杨, 花, 杏, 槐, 垂, 营, 草, 釭,\n",
      "Nearest to 歌: 欢, 话, 箫, 唱, 阇, 播, 舞, 帚,\n",
      "Nearest to 日: 夕, 月, 午, 昼, 话, 魔, 向, 况,\n",
      "Nearest to 好: 佳, 春, 缺, 哥, 你, 恍, 值, 喜,\n",
      "Nearest to 雨: 縠, 淝, 雪, 躇, 秤, 霭, 夏, 芭,\n",
      "Nearest to 重: 再, 叠, 同, 端, 沚, 珈, 瓦, 慵,\n",
      "Nearest to 心: 勺, 嗟, 缣, 术, 意, 哉, 已, 檥,\n",
      "Nearest to 子: 曙, 点, 韩, 批, 洼, 史, 踏, 峥,\n",
      "Average loss at step  302000 :  3.95698039114\n",
      "Average loss at step  304000 :  3.93679302597\n",
      "Average loss at step  306000 :  3.94069952524\n",
      "Average loss at step  308000 :  3.93607354343\n",
      "Average loss at step  310000 :  3.95604526937\n",
      "Nearest to 香: 熏, 炷, 麝, 泞, 斝, 芳, 兽, 帐,\n",
      "Nearest to 长: 常, 当, 永, 申, 际, 懋, 平, 跎,\n",
      "Nearest to 东: 西, 北, 南, 阆, 刚, 嫦, 讹, 薰,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 仍, 否, 那, 争,\n",
      "Nearest to 夜: 宵, 栩, 晓, 至, 夕, 靸, 对, 坐,\n",
      "Nearest to 自: 便, 记, 应, 脯, 零, 俱, 疑, 私,\n",
      "Nearest to 云: 霭, 墩, 曙, 雾, 撤, 窈, 烟, 睚,\n",
      "Nearest to 此: 之, 慎, 割, 偏, 今, 挫, 且, 每,\n",
      "Nearest to 柳: 杨, 杏, 槐, 竹, 垂, 釭, 梅, 湩,\n",
      "Nearest to 歌: 欢, 阇, 话, 箫, 唱, 帚, 播, 咽,\n",
      "Nearest to 日: 夕, 月, 况, 代, 午, 垆, 魔, 话,\n",
      "Nearest to 好: 佳, 你, 哥, 春, 恍, 缺, 喜, 值,\n",
      "Nearest to 雨: 縠, 雪, 躇, 淝, 粤, 霭, 秤, 迩,\n",
      "Nearest to 重: 再, 叠, 呢, 沚, 襄, 甬, 端, 同,\n",
      "Nearest to 心: 勺, 缣, 术, 哉, 嗟, 意, 神, 劈,\n",
      "Nearest to 子: 点, 头, 韩, 批, 姜, 阕, 史, 洼,\n",
      "Average loss at step  312000 :  3.96735588849\n",
      "Average loss at step  314000 :  4.03124284446\n",
      "Average loss at step  316000 :  4.01527427161\n",
      "Average loss at step  318000 :  4.02688832057\n",
      "Average loss at step  320000 :  4.01810372269\n",
      "Nearest to 香: 熏, 炷, 麝, 芳, 花, 帐, 泞, 兽,\n",
      "Nearest to 长: 永, 常, 当, 际, 应, 正, 申, 平,\n",
      "Nearest to 东: 西, 阆, 南, 刚, 北, 薰, 嫦, 斜,\n",
      "Nearest to 谁: 还, 岂, 焉, 仍, 争, 否, 我, 那,\n",
      "Nearest to 夜: 宵, 栩, 晓, 近, 夕, 坐, a, 对,\n",
      "Nearest to 自: 记, 应, 便, 疑, 最, 脯, 正, 穆,\n",
      "Nearest to 云: 霭, 窈, 墩, 撤, 枣, 雾, 嶂, 鸾,\n",
      "Nearest to 此: 之, 慎, 割, 今, 偏, 也, 挫, 或,\n",
      "Nearest to 柳: 杨, 杏, 槐, 垂, 花, 草, 竹, 釭,\n",
      "Nearest to 歌: 欢, 阇, 箫, 唱, 播, 话, 舞, 帚,\n",
      "Nearest to 日: 夕, 月, 午, 朝, 况, 魔, 时, 话,\n",
      "Nearest to 好: 佳, 春, 哥, 缺, 你, 恍, 值, 喜,\n",
      "Nearest to 雨: 縠, 躇, 雪, 淝, 秤, 粤, 迩, 芭,\n",
      "Nearest to 重: 再, 叠, 同, 端, 襄, 还, 甬, 跖,\n",
      "Nearest to 心: 勺, 缣, 术, 嗟, 檥, 哉, 已, 劈,\n",
      "Nearest to 子: 韩, 史, 瑾, 洼, 批, 阕, 曙, 点,\n",
      "Average loss at step  322000 :  3.98380591464\n",
      "Average loss at step  324000 :  4.0189777509\n",
      "Average loss at step  326000 :  4.01407932019\n",
      "Average loss at step  328000 :  3.93849523222\n",
      "Average loss at step  330000 :  3.92936202359\n",
      "Nearest to 香: 熏, 麝, 炷, 芳, 花, 泞, 腻, 斝,\n",
      "Nearest to 长: 常, 永, 际, 正, 当, 跎, 应, 鲐,\n",
      "Nearest to 东: 西, 南, 北, 阆, 刚, 嫦, 漂, 蔷,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 仍, 争, 罕, 难,\n",
      "Nearest to 夜: 宵, 栩, 晓, 梦, 坐, 更, 对, 夕,\n",
      "Nearest to 自: 记, 私, 人, 疑, 应, 便, 为, 脯,\n",
      "Nearest to 云: 霭, 撤, 雾, 窈, 墩, 曙, 烟, 霞,\n",
      "Nearest to 此: 之, 慎, 割, 今, 偏, 挫, 也, 旧,\n",
      "Nearest to 柳: 杨, 杏, 花, 槐, 垂, 堤, 草, 营,\n",
      "Nearest to 歌: 唱, 欢, 箫, 话, 播, 阇, 舞, 帚,\n",
      "Nearest to 日: 夕, 月, 午, 昼, 况, 魔, 向, 话,\n",
      "Nearest to 好: 春, 缺, 佳, 哥, 恍, 你, 值, 喜,\n",
      "Nearest to 雨: 縠, 淝, 雪, 躇, 秤, 霭, 夏, 粤,\n",
      "Nearest to 重: 再, 叠, 端, 同, 珈, 沚, 慵, 瓦,\n",
      "Nearest to 心: 勺, 嗟, 缣, 术, 檥, 哉, 意, 已,\n",
      "Nearest to 子: 曙, 韩, 点, 洼, 批, 踏, 姜, 责,\n",
      "Average loss at step  332000 :  3.96750754154\n",
      "Average loss at step  334000 :  3.9167276926\n",
      "Average loss at step  336000 :  3.92636595666\n",
      "Average loss at step  338000 :  3.93178574079\n",
      "Average loss at step  340000 :  3.94132637715\n",
      "Nearest to 香: 熏, 麝, 炷, 芳, 兽, 泞, 斝, 犀,\n",
      "Nearest to 长: 常, 永, 当, 际, 申, 平, 懋, 宜,\n",
      "Nearest to 东: 西, 北, 南, 阆, 刚, 嫦, 斜, 漂,\n",
      "Nearest to 谁: 还, 岂, 我, 仍, 焉, 那, 君, 争,\n",
      "Nearest to 夜: 宵, 栩, 至, 夕, 靸, 晓, 坐, 近,\n",
      "Nearest to 自: 便, 记, 应, 脯, 疑, 俱, 也, 零,\n",
      "Nearest to 云: 霭, 曙, 雾, 墩, 撤, 窈, 烟, 坑,\n",
      "Nearest to 此: 之, 慎, 割, 偏, 也, 今, 每, 挫,\n",
      "Nearest to 柳: 杨, 杏, 槐, 竹, 梅, 垂, 釭, 堤,\n",
      "Nearest to 歌: 欢, 唱, 箫, 阇, 帚, 播, 话, 佚,\n",
      "Nearest to 日: 月, 夕, 垆, 况, 代, 魔, 疾, 菊,\n",
      "Nearest to 好: 佳, 恍, 春, 哥, 你, 喜, 缺, 值,\n",
      "Nearest to 雨: 縠, 雪, 躇, 淝, 粤, 霭, 露, 秤,\n",
      "Nearest to 重: 再, 叠, 甬, 呢, 襄, 沚, 珈, 同,\n",
      "Nearest to 心: 勺, 缣, 术, 嗟, 哉, 意, 檥, 已,\n",
      "Nearest to 子: 韩, 点, 洼, 批, 姜, 鸪, 头, 阕,\n",
      "Average loss at step  342000 :  3.97364139462\n",
      "Average loss at step  344000 :  4.01716121304\n",
      "Average loss at step  346000 :  3.99992164183\n",
      "Average loss at step  348000 :  4.03623987865\n",
      "Average loss at step  350000 :  3.99916138387\n",
      "Nearest to 香: 熏, 炷, 麝, 芳, 帐, 兽, 花, 斝,\n",
      "Nearest to 长: 永, 当, 常, 际, 平, 黯, 弯, 绸,\n",
      "Nearest to 东: 西, 南, 阆, 北, 刚, 嫦, 薰, 漂,\n",
      "Nearest to 谁: 还, 岂, 焉, 仍, 那, 争, 我, 否,\n",
      "Nearest to 夜: 宵, 栩, 晓, 夕, 坐, 近, 靸, 对,\n",
      "Nearest to 自: 记, 应, 便, 疑, 脯, 最, 穆, 共,\n",
      "Nearest to 云: 霭, 窈, 墩, 撤, 枣, 扰, 雾, 嶂,\n",
      "Nearest to 此: 之, 慎, 割, 今, 偏, 也, 挫, 或,\n",
      "Nearest to 柳: 杨, 杏, 垂, 槐, 草, 竹, 花, 营,\n",
      "Nearest to 歌: 唱, 阇, 箫, 欢, 话, 播, 舞, 曲,\n",
      "Nearest to 日: 夕, 月, 时, 午, 魔, 朝, 是, 况,\n",
      "Nearest to 好: 佳, 哥, 缺, 春, 喜, 你, 恍, 值,\n",
      "Nearest to 雨: 縠, 秤, 躇, 淝, 芭, 雪, 粤, 泄,\n",
      "Nearest to 重: 再, 叠, 同, 还, 甬, 呢, 襄, 端,\n",
      "Nearest to 心: 勺, 缣, 术, 嗟, 檥, 哉, 劈, 意,\n",
      "Nearest to 子: 韩, 洼, 史, 点, 瑾, 弘, 曙, 头,\n",
      "Average loss at step  352000 :  3.98679428864\n",
      "Average loss at step  354000 :  4.00846377361\n",
      "Average loss at step  356000 :  4.00789138007\n",
      "Average loss at step  358000 :  3.90138690221\n",
      "Average loss at step  360000 :  3.9401743145\n",
      "Nearest to 香: 熏, 麝, 炷, 芳, 泞, 揉, 斝, 花,\n",
      "Nearest to 长: 常, 永, 当, 际, 正, 跎, 黯, 申,\n",
      "Nearest to 东: 西, 南, 北, 刚, 阆, 嫦, 漂, 蔷,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 仍, 争, 罕, 那,\n",
      "Nearest to 夜: 宵, 栩, 晓, 夕, 更, 坐, 梦, 至,\n",
      "Nearest to 自: 记, 便, 应, 疑, 私, 人, 虽, 最,\n",
      "Nearest to 云: 霭, 雾, 墩, 烟, 霞, 曙, 窈, 撤,\n",
      "Nearest to 此: 之, 慎, 割, 偏, 今, 也, 挫, 每,\n",
      "Nearest to 柳: 杨, 杏, 花, 槐, 堤, 垂, 草, 营,\n",
      "Nearest to 歌: 欢, 唱, 箫, 播, 话, 阇, 帚, 舷,\n",
      "Nearest to 日: 夕, 月, 午, 昼, 况, 话, 疾, 向,\n",
      "Nearest to 好: 佳, 缺, 恍, 哥, 春, 喜, 你, 值,\n",
      "Nearest to 雨: 縠, 霭, 淝, 雪, 秤, 躇, 芭, 粤,\n",
      "Nearest to 重: 再, 叠, 同, 瓦, 珈, 端, 沚, 呢,\n",
      "Nearest to 心: 勺, 嗟, 缣, 术, 意, 檥, 哉, 已,\n",
      "Nearest to 子: 洼, 韩, 曙, 点, 踏, 批, 姜, 柜,\n",
      "Average loss at step  362000 :  3.95405323744\n",
      "Average loss at step  364000 :  3.90000695002\n",
      "Average loss at step  366000 :  3.9233228271\n",
      "Average loss at step  368000 :  3.94118068361\n",
      "Average loss at step  370000 :  3.92455390728\n",
      "Nearest to 香: 熏, 麝, 炷, 芳, 斝, 泞, 馥, 兽,\n",
      "Nearest to 长: 常, 永, 当, 际, 申, 懋, 髀, 平,\n",
      "Nearest to 东: 西, 北, 南, 阆, 刚, 嫦, 漂, 斜,\n",
      "Nearest to 谁: 还, 岂, 我, 仍, 焉, 争, 否, 那,\n",
      "Nearest to 夜: 宵, 栩, 夕, 靸, 至, 晓, 坐, 对,\n",
      "Nearest to 自: 便, 应, 脯, 记, 疑, 零, 也, 俱,\n",
      "Nearest to 云: 霭, 雾, 曙, 墩, 撤, 窈, 烟, 鸾,\n",
      "Nearest to 此: 割, 之, 慎, 偏, 今, 挫, 每, 它,\n",
      "Nearest to 柳: 杨, 杏, 槐, 竹, 梅, 釭, 垂, 堤,\n",
      "Nearest to 歌: 欢, 唱, 箫, 阇, 播, 帚, 话, 舷,\n",
      "Nearest to 日: 月, 夕, 况, 垆, 菊, 狠, 代, 疾,\n",
      "Nearest to 好: 喜, 佳, 恍, 哥, 你, 缺, 春, 值,\n",
      "Nearest to 雨: 縠, 雪, 躇, 粤, 淝, 霭, 秤, 露,\n",
      "Nearest to 重: 再, 叠, 呢, 甬, 襄, 珈, 沚, 同,\n",
      "Nearest to 心: 勺, 缣, 术, 嗟, 哉, 意, 檥, 欲,\n",
      "Nearest to 子: 批, 韩, 洼, 姜, 头, 鸪, 点, 庄,\n",
      "Average loss at step  372000 :  3.96102309728\n",
      "Average loss at step  374000 :  4.00846667361\n",
      "Average loss at step  376000 :  3.98711294127\n",
      "Average loss at step  378000 :  4.02000767636\n",
      "Average loss at step  380000 :  4.00871854293\n",
      "Nearest to 香: 熏, 炷, 麝, 芳, 花, 帐, 泞, 斝,\n",
      "Nearest to 长: 永, 当, 常, 际, 平, 绸, 正, 申,\n",
      "Nearest to 东: 西, 阆, 北, 南, 刚, 嫦, 薰, 斜,\n",
      "Nearest to 谁: 还, 岂, 焉, 仍, 那, 我, 罕, 否,\n",
      "Nearest to 夜: 宵, 栩, 晓, 夕, 坐, 近, 靸, 对,\n",
      "Nearest to 自: 记, 应, 便, 最, 脯, 疑, 共, 又,\n",
      "Nearest to 云: 霭, 墩, 窈, 撤, 烟, 嶂, 坑, 雾,\n",
      "Nearest to 此: 之, 慎, 今, 割, 也, 偏, 挫, 或,\n",
      "Nearest to 柳: 杨, 花, 杏, 槐, 垂, 竹, 草, 绿,\n",
      "Nearest to 歌: 唱, 阇, 箫, 欢, 播, 话, 舞, 帚,\n",
      "Nearest to 日: 夕, 月, 时, 午, 是, 朝, 况, 垆,\n",
      "Nearest to 好: 佳, 哥, 喜, 缺, 恍, 值, 你, 要,\n",
      "Nearest to 雨: 縠, 淝, 芭, 秤, 躇, 粤, 雪, 番,\n",
      "Nearest to 重: 再, 叠, 甬, 端, 同, 还, 呢, 跖,\n",
      "Nearest to 心: 勺, 术, 缣, 嗟, 檥, 哉, 意, 欲,\n",
      "Nearest to 子: 洼, 韩, 瑾, 史, 弘, 踯, 批, 头,\n",
      "Average loss at step  382000 :  3.97509001231\n",
      "Average loss at step  384000 :  4.00416869783\n",
      "Average loss at step  386000 :  3.9935097363\n",
      "Average loss at step  388000 :  3.88540387022\n",
      "Average loss at step  390000 :  3.92411514699\n",
      "Nearest to 香: 熏, 麝, 炷, 芳, 花, 泞, 揉, 斝,\n",
      "Nearest to 长: 永, 常, 当, 际, 正, 跎, 黯, 鲐,\n",
      "Nearest to 东: 西, 南, 北, 刚, 阆, 嫦, 漂, 蔷,\n",
      "Nearest to 谁: 还, 岂, 焉, 我, 仍, 争, 那, 怎,\n",
      "Nearest to 夜: 宵, 栩, 更, 夕, 晓, 坐, 梦, 对,\n",
      "Nearest to 自: 记, 应, 便, 疑, 最, 虽, 私, 人,\n",
      "Nearest to 云: 霭, 雾, 霞, 撤, 墩, 曙, 鸾, 烟,\n",
      "Nearest to 此: 之, 慎, 今, 割, 偏, 也, 挫, 每,\n",
      "Nearest to 柳: 杨, 花, 杏, 草, 槐, 堤, 垂, 营,\n",
      "Nearest to 歌: 欢, 唱, 箫, 帚, 话, 阇, 播, 舞,\n",
      "Nearest to 日: 夕, 月, 午, 昼, 况, 话, 向, 垆,\n",
      "Nearest to 好: 佳, 恍, 缺, 哥, 喜, 要, 你, 春,\n",
      "Nearest to 雨: 縠, 霭, 雪, 淝, 秤, 躇, 芭, 粤,\n",
      "Nearest to 重: 再, 叠, 同, 甬, 珈, 瓦, 沚, 呢,\n",
      "Nearest to 心: 勺, 嗟, 缣, 术, 檥, 意, 哉, 丧,\n",
      "Nearest to 子: 洼, 韩, 曙, 批, 姜, 头, 踏, 点,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  392000 :  3.96050935972\n",
      "Average loss at step  394000 :  3.89490509319\n",
      "Average loss at step  396000 :  3.9203535924\n",
      "Average loss at step  398000 :  3.92988498199\n",
      "Average loss at step  400000 :  3.92623918974\n",
      "Nearest to 香: 熏, 麝, 炷, 芳, 泞, 斝, 兽, 馥,\n",
      "Nearest to 长: 永, 常, 当, 懋, 平, 际, 申, 髀,\n",
      "Nearest to 东: 西, 南, 北, 阆, 刚, 嫦, 漂, 蔷,\n",
      "Nearest to 谁: 还, 仍, 岂, 我, 焉, 那, 否, 争,\n",
      "Nearest to 夜: 宵, 栩, 夕, 晓, 靸, 坐, 对, 至,\n",
      "Nearest to 自: 应, 便, 脯, 最, 记, 虽, 疑, 也,\n",
      "Nearest to 云: 霭, 墩, 雾, 撤, 曙, 睚, 鸾, 欤,\n",
      "Nearest to 此: 之, 割, 慎, 偏, 今, 挫, 它, 每,\n",
      "Nearest to 柳: 杨, 杏, 槐, 竹, 堤, 花, 梅, 草,\n",
      "Nearest to 歌: 唱, 欢, 箫, 阇, 帚, 话, 播, 舷,\n",
      "Nearest to 日: 夕, 月, 况, 垆, 午, 菊, 狠, ,\n",
      "Nearest to 好: 喜, 佳, 恍, 哥, 缺, 春, 值, 要,\n",
      "Nearest to 雨: 縠, 雪, 霭, 淝, 粤, 躇, 露, 番,\n",
      "Nearest to 重: 再, 叠, 甬, 呢, 珈, 襄, 沚, 同,\n",
      "Nearest to 心: 勺, 缣, 术, 哉, 意, 嗟, 欲, 檥,\n",
      "Nearest to 子: 韩, 洼, 鸪, 批, 头, 社, 弘, 点,\n"
     ]
    }
   ],
   "source": [
    "with tf.Session(graph=graph) as session:\n",
    "  # We must initialize all variables before we use them.\n",
    "  init.run()\n",
    "  print('Initialized')\n",
    "\n",
    "  average_loss = 0\n",
    "  for step in xrange(num_steps):\n",
    "    batch_inputs, batch_labels = generate_batch(\n",
    "        batch_size, num_skips, skip_window)\n",
    "    feed_dict = {train_inputs: batch_inputs, train_labels: batch_labels}\n",
    "\n",
    "    # We perform one update step by evaluating the optimizer op (including it\n",
    "    # in the list of returned values for session.run()\n",
    "    _, loss_val = session.run([optimizer, loss], feed_dict=feed_dict)\n",
    "    average_loss += loss_val\n",
    "\n",
    "    if step % 2000 == 0:\n",
    "      if step > 0:\n",
    "        average_loss /= 2000\n",
    "      # The average loss is an estimate of the loss over the last 2000 batches.\n",
    "      print('Average loss at step ', step, ': ', average_loss)\n",
    "      average_loss = 0\n",
    "\n",
    "    # Note that this is expensive (~20% slowdown if computed every 500 steps)\n",
    "    if step % 10000 == 0:\n",
    "      sim = similarity.eval()\n",
    "      for i in xrange(valid_size):\n",
    "        valid_word = reverse_dictionary[valid_examples[i]]\n",
    "        top_k = 8  # number of nearest neighbors\n",
    "        nearest = (-sim[i, :]).argsort()[1:top_k + 1]\n",
    "        log_str = 'Nearest to %s:' % valid_word\n",
    "        for k in xrange(top_k):\n",
    "          close_word = reverse_dictionary[nearest[k]]\n",
    "          log_str = '%s %s,' % (log_str, close_word)\n",
    "        print(log_str)\n",
    "  final_embeddings = normalized_embeddings.eval()\n",
    "  np.save('embedding.npy', final_embeddings)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# data, count, dictionary, reverse_dictionary\n",
    "with open(\"dictionary.json\",'w', encoding=\"utf-8\") as f:\n",
    "  f.write(json.dumps(dictionary))\n",
    "with open(\"reverse_dictionary.json\",'w', encoding=\"utf-8\") as f:\n",
    "  f.write(json.dumps(reverse_dictionary))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"dictionary2.json\",'w', encoding=\"utf-8\") as f:\n",
    "  json.dump(dictionary,f)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open(\"data.json\",'w', encoding=\"utf-8\") as f:\n",
    "  json.dump(data,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_with_labels(low_dim_embs, labels, filename):\n",
    "  assert low_dim_embs.shape[0] >= len(labels), 'More labels than embeddings'\n",
    "  plt.figure(figsize=(18, 18))  # in inches\n",
    "  for i, label in enumerate(labels):\n",
    "    x, y = low_dim_embs[i, :]\n",
    "    plt.scatter(x, y)\n",
    "    plt.annotate(label,\n",
    "                 xy=(x, y),\n",
    "                 xytext=(5, 2),\n",
    "                 textcoords='offset points',\n",
    "                 ha='right',\n",
    "                 va='bottom')\n",
    "\n",
    "  plt.savefig(filename)\n",
    "\n",
    "try:\n",
    "  # pylint: disable=g-import-not-at-top\n",
    "  from sklearn.manifold import TSNE\n",
    "  import matplotlib.pyplot as plt\n",
    "\n",
    "  tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000, method='exact')\n",
    "  plot_only = 500\n",
    "  low_dim_embs = tsne.fit_transform(final_embeddings[:plot_only, :])\n",
    "  labels = [reverse_dictionary[i] for i in xrange(plot_only)]\n",
    "  plot_with_labels(low_dim_embs, labels, os.path.join(gettempdir(), 'tsne.png'))\n",
    "\n",
    "except ImportError as ex:\n",
    "  print('Please install sklearn, matplotlib, and scipy to show embeddings.')\n",
    "  print(ex)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "def test1(voca,bat,num):\n",
    "    voca=[voca[i:i+num] for i in range(len(voca)-num+1)]\n",
    "    x=voca[:-1]\n",
    "    y=voca[1:]\n",
    "#     print(\"x:\",x)\n",
    "#     print(\"y:\",y)\n",
    "    x,y=tf.train.batch([x,y],batch_size=4)\n",
    "    return x,y\n",
    "    dy=len(x)%bat\n",
    "    if dy!=0:\n",
    "        x=np.reshape(x[:-dy],[-1,bat,num])\n",
    "        y=np.reshape(y[:-dy],[-1,bat,num])\n",
    "    else:\n",
    "        x=np.reshape(x,[-1,bat,num])\n",
    "        y=np.reshape(y,[-1,bat,num])\n",
    "#     print(\"x:\",x)\n",
    "#     print(\"y:\",y)\n",
    "    return zip(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def test2(voca,bat,num):\n",
    "    raw_x=voca[:-1]\n",
    "    raw_y=voca[1:]\n",
    "    data_partition_size = len(raw_x)//bat\n",
    "    data_x = np.zeros([bat,data_partition_size],dtype=np.int32)\n",
    "    data_y = np.zeros([bat,data_partition_size],dtype=np.int32)\n",
    "    for i in range(bat):\n",
    "        data_x[i] = raw_x[data_partition_size*i:data_partition_size*(i+1)]\n",
    "        data_y[i] = raw_y[data_partition_size*i:data_partition_size*(i+1)]\n",
    "    epoch_size = data_partition_size//num\n",
    "    for i in range(epoch_size):\n",
    "        x = data_x[:,i*num:(i+1)*num]\n",
    "        y = data_y[:,i*num:(i+1)*num]\n",
    "        yield (x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [33 34 35 36]\n",
      " [66 67 68 69]] [[ 1  2  3  4]\n",
      " [34 35 36 37]\n",
      " [67 68 69 70]]\n",
      "[[ 4  5  6  7]\n",
      " [37 38 39 40]\n",
      " [70 71 72 73]] [[ 5  6  7  8]\n",
      " [38 39 40 41]\n",
      " [71 72 73 74]]\n",
      "[[ 8  9 10 11]\n",
      " [41 42 43 44]\n",
      " [74 75 76 77]] [[ 9 10 11 12]\n",
      " [42 43 44 45]\n",
      " [75 76 77 78]]\n",
      "[[12 13 14 15]\n",
      " [45 46 47 48]\n",
      " [78 79 80 81]] [[13 14 15 16]\n",
      " [46 47 48 49]\n",
      " [79 80 81 82]]\n",
      "[[16 17 18 19]\n",
      " [49 50 51 52]\n",
      " [82 83 84 85]] [[17 18 19 20]\n",
      " [50 51 52 53]\n",
      " [83 84 85 86]]\n",
      "[[20 21 22 23]\n",
      " [53 54 55 56]\n",
      " [86 87 88 89]] [[21 22 23 24]\n",
      " [54 55 56 57]\n",
      " [87 88 89 90]]\n",
      "[[24 25 26 27]\n",
      " [57 58 59 60]\n",
      " [90 91 92 93]] [[25 26 27 28]\n",
      " [58 59 60 61]\n",
      " [91 92 93 94]]\n",
      "[[28 29 30 31]\n",
      " [61 62 63 64]\n",
      " [94 95 96 97]] [[29 30 31 32]\n",
      " [62 63 64 65]\n",
      " [95 96 97 98]]\n"
     ]
    }
   ],
   "source": [
    "voca=[i for i in range(102)]\n",
    "dl=test2(voca,3,4)\n",
    "for i in dl:\n",
    "    print(i[0],i[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "c\n",
      "a\n",
      "c\n",
      "c\n",
      "c\n",
      "d\n",
      "d\n",
      "c\n",
      "d\n"
     ]
    }
   ],
   "source": [
    "def probsToWord(weights, words):  \n",
    "    \"\"\"probs to word\"\"\"  \n",
    "    t = np.cumsum(weights) #prefix sum  \n",
    "    s = np.sum(weights)  \n",
    "    coff = np.random.rand(1)  \n",
    "    index = int(np.searchsorted(t, coff * s))\n",
    "    return words[index]\n",
    "    \n",
    "weightslist=[0.1,0.1,0.4,0.4]\n",
    "words=['a','b','c','d']\n",
    "for i in range(10):\n",
    "    print(probsToWord(weightslist,words))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
